import csv
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns


train = pd.read_csv('train.csv')
test = pd.read_csv('test.csv')

alldata = pd.concat((train.loc[:,'MSSubClass':'SaleCondition'],test.loc[:,'MSSubClass':'SaleCondition']),ignore_index=True)
# print(alldata.shape)

# explore = train.describe(include = 'all').T
# explore['null'] = len(train) - explore['count']
# explore.insert(0,'dtype',train.dtypes)
# explore.T.to_csv('explore1.csv')

# print(train.describe().T)

# explore.T.to_csv('explore1.csv')


corrmat = train.corr()
plt.subplots(figsize=(12,9))
sns.heatmap(corrmat, vmax=0.9, square=True)
# plt.show()


#查看影响最终价格的十个变量
k = 10
plt.figure(figsize=(12,9))
cols = corrmat.nlargest(k, 'SalePrice')['SalePrice'].index
cm = np.corrcoef(train[cols].values.T)
sns.set(font_scale=1.25)
hm = sns.heatmap(cm, cbar=True, annot=True, square=True, fmt='.2f', annot_kws={'size': 10}, yticklabels=cols.values, xticklabels=cols.values)
# plt.show()


Corr = train.corr()
# print(Corr[Corr['SalePrice']>0.5])


#scatterplot 绘制散点图矩阵注意：多变量作图数据中不能有空值，否则出错
sns.set()
cols = ['SalePrice', 'OverallQual', 'GrLivArea', 'GarageCars', 'TotalBsmtSF', 'FullBath', 'YearBuilt']
sns.pairplot(train[cols], size = 2.5)
plt.show()

train['SalePrice'].describe()

# histogram画直方图,且查看数据是否符合正态分布
# 直方图和正态概率图
# sns.distplot(train['SalePrice'], fit='norm')
# fig = plt.figure()
# res = stats.probplot(train['SalePrice'], plot=plt)

#  由图像可知，图像的非正态分布
